package com.zq.server.api.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.zq.server.api.domain.entity.ApiUserTag;
import com.zq.server.api.domain.vo.TagListVo;

/**
 * @author Super
 * @description 针对表【user_tag】的数据库操作Mapper
 * @createDate 2024-03-04 00:48:08
 * @Entity com.zq.daomain.entity.UserTag
 */

@Mapper
public interface UserTagMapper {

    /**
     * 根据用户id获取标签
     *
     * @param userId
     * @return
     */
    @Select("select  tag_id from api_user_tag where user_id = #{userId}")
    int[] getUserTagListByUserId(Long userId);

    /**
     * 添加标签 批量
     *
     * @param TagList
     * @return
     */
    Boolean saveListByTagId(@Param("TagList") List<ApiUserTag> TagList);


    /**
     * 删除不需要的标签
     *
     * @param userId
     * @param cancelTagIds
     */
    Boolean deleteTagsByUserIdAndTagIds(Long userId, List<Integer> cancelTagIds);

    /**
     * 删除所有标签
     *
     * @param userId Boolean
     */
    @Delete("delete from  api_user_tag where user_id = #{userId}")
    Boolean deleteAllTagsByUserId(Long userId);

    /**
     * 获取用户所有tag
     *
     * @param userId
     * @return
     */
    @Select("  SELECT t.tag_name,t.id FROM api_user_tag AS u\n" +
            "                 JOIN api_tag AS t ON u.tag_id = t.id where u.user_id = #{userId}")
    List<TagListVo> getUserTagList(@Param("userId") Long userId);

}
